package com.itic.mall.mobile.yh;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.utils.CalendarHelper;
import com.itic.appbase.framework.utils.DateHelper;
import com.itic.appbase.framework.utils.IpAddressHelper;
import com.itic.appbase.framework.utils.NumericHelper;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.appbase.framework.utils.ValueHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.mobile.goods.vo.GoodsDetailBannerVo;
import com.itic.mall.mobile.goods.vo.GoodsPropertyVo;
import com.itic.mall.mobile.goods.vo.GoodsSkuVo;
import com.itic.mall.system.goods.goodscategory.persistence.model.GoodsCategory;
import com.itic.mall.system.goods.goodscategory.persistence.model.GoodsCategoryExample;
import com.itic.mall.system.goods.goodscategory.service.GoodsCategoryService;
import com.itic.mall.system.goods.goodssku.persistence.model.GoodsSku;
import com.itic.mall.system.goods.goodssku.persistence.model.GoodsSkuExample;
import com.itic.mall.system.goods.goodssku.service.GoodsSkuService;
import com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpu;
import com.itic.mall.system.goods.propertyvalue.persistence.model.PropertyValueVo;
import com.itic.mall.system.goods.propertyvalue.service.PropertyValueService;
import com.itic.mall.system.goods.skucommission.persistence.model.SkuCommission;
import com.itic.mall.system.goods.skucommission.persistence.model.SkuCommissionExample;
import com.itic.mall.system.goods.skucommission.service.SkuCommissionService;
import com.itic.mall.system.goods.skucoupon.persistence.model.SkuCoupon;
import com.itic.mall.system.goods.skucoupon.persistence.model.SkuCouponExample;
import com.itic.mall.system.goods.skucoupon.service.SkuCouponService;
import com.itic.mall.system.goods.skuproperty.persistence.model.SkuProperty;
import com.itic.mall.system.goods.skuproperty.persistence.model.SkuPropertyExample;
import com.itic.mall.system.goods.skuproperty.persistence.model.SkuPropertyVo;
import com.itic.mall.system.goods.skuproperty.service.SkuPropertyService;
import com.itic.mall.system.goods.spufeedback.persistence.model.SpuFeedback;
import com.itic.mall.system.goods.spufeedback.persistence.model.SpuFeedbackExample;
import com.itic.mall.system.goods.spufeedback.service.SpuFeedbackService;
import com.itic.mall.system.goods.spuopen.persistence.model.SpuOpen;
import com.itic.mall.system.goods.spuopen.persistence.model.SpuOpenExample;
import com.itic.mall.system.goods.spuopen.service.SpuOpenService;
import com.itic.mall.system.goods.spuspec.persistence.model.SpuSpec;
import com.itic.mall.system.goods.spuspec.persistence.model.SpuSpecExample;
import com.itic.mall.system.goods.spuspec.service.SpuSpecService;
import com.itic.mall.system.market.marketarrondi.service.MarketArrondiService;
import com.itic.mall.system.market.marketspecial.persistence.model.MarketSpecial;
import com.itic.mall.system.market.marketspecial.service.MarketSpecialService;
import com.itic.mall.system.users.usercoupon.persistence.model.UsersCoupon;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMall;

/**
 * 友惠中心
 * 
 * @author 许小宝
 * @date 2017年12月22日 上午10:33:24
 */
@Controller
@RequestMapping(value = "/mobile/yh")
public class YhInterface extends BaseMobileInterface {

	@Autowired
	protected MarketArrondiService marketArrondiService;
	
	@Autowired
	private GoodsCategoryService goodsCategoryService;
	
	@Autowired
	private SkuCouponService skuCouponService;
	
	@Autowired
	private SkuCommissionService skuCommissionService;
	
	@Autowired
	private SpuOpenService spuOpenService;
	
	@Autowired
	private SkuPropertyService skuPropertyService;
	
	@Autowired
	private PropertyValueService propertyValueService;
	
	@Autowired
	private SpuSpecService spuSpecService;
	
	@Autowired
	private SpuFeedbackService spuFeedbackService;
	
	@Autowired
	private GoodsSkuService goodsSkuService;
	
	@Autowired
	private MarketSpecialService marketSpecialService;
	
	
	/**
	    * APP首页大分类搜索
	    * @return
	    */
	   @RequestMapping(value="/index")
	   @ResponseBody
	   public Map<String,Object> index( HttpServletRequest request,HttpServletResponse response){
		    Map<String, Object> resultMap = new HashMap<String,Object>();
		   	String errorCode = PARAM_ERROR_CODE;
		   	String errorMsg = PARAM_ERROR_MSG;
		   	try{
		   		GoodsCategoryExample example = new GoodsCategoryExample();
		   		example.setOrderByClause("REORDER ASC");
		   		com.itic.mall.system.goods.goodscategory.persistence.model.GoodsCategoryExample.Criteria criteria = example.createCriteria();
		   		
		   		criteria.andTypeEqualTo("yh"); //002  友惠分类
		   		
		   		List<GoodsCategory> list = goodsCategoryService.list(example);
		   		resultMap.put(DATA, ValueHelper.tranList2MapList(list, new String[] { "note","reorder","categoryCode","createUser", "isEffective", "updateTime", "orgCode","isVisible","createTime","categoryPid"}));
		   		errorCode = SUCCESS_ERROR_CODE;
		       	errorMsg = SUCCESS_ERROR_MSG;
		   	}catch(Exception e){
		   		errorCode = SERVER_ERROR_CODE;
		       	errorMsg = SERVER_ERROR_MSG;
		   		logException("YhInterface", "categorys", e.toString(),"友惠家的分类",e);
		   	}
		   	resultMap.put(CODE, errorCode);
		   	resultMap.put(MSG, errorMsg);
		   	isCrrossDomain(response);
		   	return resultMap;
	   }

	
	
	  /**
	    * APP首页大分类搜索
	    * @return
	    */
	   @RequestMapping(value="/categorys")
	   @ResponseBody
	   public Map<String,Object> category( HttpServletRequest request,HttpServletResponse response){
		    Map<String, Object> resultMap = new HashMap<String,Object>();
		   	String errorCode = PARAM_ERROR_CODE;
		   	String errorMsg = PARAM_ERROR_MSG;
		   	try{
		   		resultMap.put(DATA, getTopCategorysByType("yh"));
		   		errorCode = SUCCESS_ERROR_CODE;
		       	errorMsg = SUCCESS_ERROR_MSG;
		   	}catch(Exception e){
		   		errorCode = SERVER_ERROR_CODE;
		       	errorMsg = SERVER_ERROR_MSG;
		   		logException("YhInterface", "categorys", e.toString(),"友惠家的分类",e);
		   	}
		   	resultMap.put(CODE, errorCode);
		   	resultMap.put(MSG, errorMsg);
		   	isCrrossDomain(response);
		   	return resultMap;
	   }

	/**
	 * 京东展示页轮播图信息
	 * 
	 * @author 许小宝
	 * @date 2017年12月22日 上午11:50:49
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/banners")
	@ResponseBody
	public Map<String, Object> banners(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			// 首页轮播图信息
			resultMap.put(DATA, getMarketBannersByType("yh"));
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("IndexInterface", "banners", e.toString(), "友惠展示页轮播图信息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 京东展示页轮播图信息
	 * 
	 * @author 王文鑫
	 * @date 2017年12月22日 上午11:50:49
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/models")
	@ResponseBody
	public Map<String, Object> models(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			// 首页轮播图信息
			resultMap.put(DATA, getMarketActivitysByType("yh"));
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("IndexInterface", "banners", e.toString(), "友惠八大模块", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 获取广告位
	 * 
	 * @author 许小宝
	 * @date 2017年12月22日 下午3:31:52
	 * @param request
	 * @param response
	 * @param address
	 * @return
	 */
	@RequestMapping(value = "/adverts")
	@ResponseBody
	public Map<String, Object> adverts(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		String errorCode = PARAM_ERROR_CODE; // 缺少必填参数
		String errorMsg = PARAM_ERROR_MSG;// 缺少必填参数，返回信息

		try {
			resultMap.put(DATA, getMarketAdvertByTypeAndAddress("yh","one"));
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			// 服务器异常处理
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			// 打印异常日志
			logException("YhInterface", "advert", e.toString(), "获取广告位", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response); // 跨域处理
		return resultMap;
	}
	
	
	
	/**
	 * 获取广告位
	 * 
	 * @author 许小宝
	 * @date 2017年12月22日 下午3:31:52
	 * @param request
	 * @param response
	 * @param address
	 * @return
	 */
	@RequestMapping(value = "/goods")
	@ResponseBody
	public Map<String, Object> goods(HttpServletRequest request, HttpServletResponse response,String type, String keyword, String categoryId, String categoryCode, String orderType, String goodsType) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		String errorCode = PARAM_ERROR_CODE; // 缺少必填参数
		String errorMsg = PARAM_ERROR_MSG;// 缺少必填参数，返回信息

		try {
			resultMap.put(DATA, getGoodsBySpuFromAndType(request,"yh",keyword,categoryId,categoryCode,orderType,goodsType));
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			// 服务器异常处理
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			// 打印异常日志
			logException("YhInterface", "goods", e.toString(), "获取商品信息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response); // 跨域处理
		return resultMap;
	}
	
	
	
	
	
	/**
	 * APP查找友惠，京东，天猫，淘宝等商品信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/spuImage")
	public String spuImage( Model model,String id ) {
		GoodsSpu goodsSpu = goodsSpuService.get(id);
		if( null != goodsSpu ){
			model.addAttribute("images", goodsSpu.getDetailImageUrls());
		}
		return "/mall/mobile/goods/spuImage";
	}

	/**
	 * APP查找友惠，京东，天猫，淘宝等商品详情信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/detail")
	@ResponseBody
	public Map<String, Object> detail(HttpServletRequest request, HttpServletResponse response, String token, String appId, String id) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if (StringHelper.isNotBlank(id)) {
				GoodsSpu spu = goodsSpuService.get(id);
				if( null != spu ){
					 //添加点击统计
  					addClick(spu);
					Date now = new Date();
					Map<String, Object> dataMap = new HashMap<String, Object>();
					
					Map<String, Object> detailPropergory = new HashMap<String, Object>();
					
					GoodsDetailBannerVo goodsDetailBannerVo = new GoodsDetailBannerVo();
					String[] split = {};
					Integer count = 0;
					if( StringHelper.isNotBlank(spu.getBanners()) ){
						String banners = spu.getBanners();
						split = banners.split(",");
					}
					goodsDetailBannerVo.setBanners(split);
					goodsDetailBannerVo.setCount(count);
					
					
					dataMap.put("banner", split);//添加轮播图片信息
					dataMap.put("bannerTip", spu.getBannerTip());//轮播图下的提示图片地址
					/*dataMap.put("goodsName", spu.getSkuName());*///商品名称
					
					dataMap.put("goodsName", spu.getGoodsName()); //商品名称
					
					//判断用户是否领取红包
					String isCoupon = "0";
					
					//通过appId token判断用户是否登录
					UsersMall usersMall = this.getUsersByTokenAndAppId(token, appId);
					List<UsersCoupon> usersCoupons=null;
					
					if(null!=usersMall){
						 //判断用户是否领取红包
						 usersCoupons = this.usersCouponService.findCouponListByUserIdAndSpuId(usersMall.getId(), id);
						 if( usersCoupons.isEmpty()){
				            	isCoupon = "0";
				            }else{
				            	isCoupon = "1";
				         }
					}
		            
		            dataMap.put("iscoupon", isCoupon); //用户红包是否已领取
					
					GoodsSku mainSku = getMainSkuBySpu(spu);
					
					detailPropergory.put("skuId", mainSku.getId());
					detailPropergory.put("skuDetails", mainSku.getSkuDetails());
					detailPropergory.put("skuPrice", mainSku.getSkuPrice());
					detailPropergory.put("totalInventory", mainSku.getTotalInventory());
					detailPropergory.put("paramQuery", mainSku.getParamQuery());
					detailPropergory.put("maxBuyNum", mainSku.getMaxBuyNum());
					detailPropergory.put("minBuyNum", mainSku.getMinBuyNum());
					detailPropergory.put("skuBanners", mainSku.getSkuBanners());
					
					String paramQuery = mainSku.getParamQuery(); //查询主款规格规格比
					StringBuffer skuPropertyVoBut = new StringBuffer(); //规格值
					
					if(paramQuery!=null){
						//判断里面是否有冒号,并且不为空
						if( paramQuery.contains(":") ){
							
							String[] paramQuerys = paramQuery.split(":");
							for (String paramQ : paramQuerys) {
								SkuProperty skuProperty = getSkuPropertyById(paramQ);
								skuPropertyVoBut.append(skuProperty.getValue());
								skuPropertyVoBut.append(",");
							}
						}else if(StringHelper.isNotBlank(paramQuery)){
							SkuProperty skuProperty = getSkuPropertyById(paramQuery);
							skuPropertyVoBut.append(skuProperty.getValue());
						}
					}
					
					if(paramQuery != null){
						String skuPropertyVoStr = skuPropertyVoBut.substring(0,skuPropertyVoBut.length() - 1);
						detailPropergory.put("skuPropertyVo", skuPropertyVoStr);
					}else{
						detailPropergory.put("skuPropertyVo", "");
					}
					
					dataMap.put("detailPropergory", detailPropergory);//添加轮播图片信息
					
					dataMap.put("price", mainSku.getSkuPrice());//商品的价格
					dataMap.put("conPrice", spu.getConPrice());//商品券后价
					
					dataMap.put("fullcuts", getCanUsedCouponBySpuAndType(spu,"fullcut"));
					
					dataMap.put("reds", getCanUsedCouponBySpuAndType(spu,"red"));
					
					dataMap.put("coupons", getCanUsedCouponBySpuAndType(spu,"coupon"));
					
					Double wlCommissionByConPrice = 0.00;
					SkuCommission commission = getWlCommissionBySku(mainSku);
					if( null != commission ){
						 wlCommissionByConPrice = getWlCommissionByConPrice(commission.getPercent(),spu.getConPrice());
					}
					if("yh".equals(spu.getSpuPlatform())){
						dataMap.put("wlCommission", spu.getWlCommission());//无线推广赚佣金多少
					}else{
						dataMap.put("wlCommission", wlCommissionByConPrice);//无线推广赚佣金多少
					}
					if("yh".equals(spu.getSpuPlatform())){
						dataMap.put("totalSales", spu.getTotalSales());//总销量，应该是所有的sku的销量
					}else{
						dataMap.put("totalSales", goodsSkuService.getTotalSalesBySpuId(spu.getId()));//总销量，应该是所有的sku的销量
					}
					dataMap.put("isFreePost", spu.getIsFreePost());//是否包邮
					dataMap.put("isQualityAssurance",spu.getIsQualityAssurance());//是否正品保证
					dataMap.put("isServenBack", spu.getIsServenBack());//是否七天退换货
					dataMap.put("isOnTime", spu.getIsOnTime());//是否准时到达
					dataMap.put("buyTip", "");//默认购买无提示图片
					dataMap.put("isCanBuy","yes");//是否可以购买
					
					dataMap.put("totalInventorys",spu.getTotalInventorys());//商品总库存
					
					if( null != spu.getOpenTime() ){
						//openTime时间是否大于开始时间，说明还没有到购买的时间
						if( CalendarHelper.isGreaterOrEqualTo(spu.getOpenTime(),now ) ){
							 //找找是否有购买提示的图片信息
							 dataMap.put("buyTip", getBuyTipBySpu(spu) );
							 dataMap.put("isCanBuy", "no");
						}
					}
					
					//获取商品的属性列表
					List<SkuProperty> skuproperty = getSkuPropertyBySpu(spu.getId());
					if(skuproperty.size()!=0){
						dataMap.put("propertys",ValueHelper.tranList2MapList(skuproperty, new String[] {"createUser","createTime", "isEffective", "updateTime", "orgCode","note","reorder","spuId","skuId","valueId","nameId","codeid","minBuyNum","skuPrice","pid","totalInventory","maxBuyNum" }));
					}else{
						dataMap.put("propertys",new ArrayList<Map<String,Object>>());
					}
					
					List<GoodsSku> goodsSku = getGoodsSkuBySpuId(spu.getId());
					dataMap.put("goodsSku",ValueHelper.tranList2MapList(goodsSku, new String[] {"createUser","createTime", "isEffective", "updateTime", "orgCode","note","reorder","skuId","valueId","nameId","skuNum","skuOrginPrice" }));
					
					
					List<SpuSpec> specs = getSpecsBySpu(spu);
					dataMap.put("specs", ValueHelper.tranList2MapList(specs, new String[] { "id","createUser","createTime", "isEffective", "updateTime", "orgCode","note","reorder","spuId" }));
					
					dataMap.put("spuImageUrl", getSpuImageBySpu(request,spu) );//商品的详情网址;
					
					dataMap.put("detailImages", spu.getDetailImageUrls().split(",") );//商品的详情数组;
					
					dataMap.put("propertyNames", getGroupPropertyNameBySpu(spu));
					dataMap.put("isBuy", 1);
					if("1".equals(spu.getIsSpecial())) {
						MarketSpecial marketSpecial = this.marketSpecialService.getMarketSpercialBySpuId(spu.getId());
						if(marketSpecial==null)
							dataMap.put("isBuy",0);
					}
					resultMap.put(DATA, dataMap);

					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_NOT_FIND_ERROR_CODE;
					errorMsg = PRODUCT_NOT_FIND_ERROR_MSG;
				}
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "detail2", e.toString(), "APP查找友惠，京东，天猫，淘宝等商品详情信息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 根据商品的spuId获得商品的属性
	 * 
	 * @return
	 */
	@RequestMapping(value = "/skuPropertys")
	@ResponseBody
	public Map<String, Object> skuPropertys(HttpServletRequest request, HttpServletResponse response, String id) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if (StringHelper.isNotBlank(id)) {
				
				GoodsSpu spu = goodsSpuService.get(id);
				if( null != spu ){
					
					Map<String, Object> dataMap = new HashMap<String, Object>();
					
					List<GoodsPropertyVo> propertys = new ArrayList<GoodsPropertyVo>();
					
					List<SkuPropertyVo> propertyVos = getGroupPropertyVoBySpu(spu);
					if( propertyVos.size()>0 ){
						for( SkuPropertyVo temp : propertyVos ){
							GoodsPropertyVo vo = new GoodsPropertyVo();
							vo.setPropertyId(temp.getNameId());
							vo.setPropertyName(temp.getName());
							//查找该属性下的值总共多少
							/*List<PropertyValueVo> valuesVos = getPropertyValueVosByNameId(temp.getNameId());
							vo.setPropertyValues(valuesVos);
							propertys.add(vo);*/
						}
					}
					
					dataMap.put("propertys", propertys);
					
					GoodsSku mainSku = getMainSkuBySpu(spu);
					GoodsSkuVo goodsSkuVo = new GoodsSkuVo();
					goodsSkuVo.setSkuId(mainSku.getId());
					goodsSkuVo.setPrice(mainSku.getSkuPrice());
					goodsSkuVo.setInventory(mainSku.getTotalInventory()-mainSku.getTotalSales());
					goodsSkuVo.setSkuImage(mainSku.getSkuBanners());
					
					List<SkuProperty> skuPropertys = getSkuPropertyValueBySku(mainSku);
					List<Map<String, Object>> skuPropertyValues = ValueHelper.tranList2MapList(skuPropertys, new String[] { "id", "note", "reorder",
							"createUser", "isEffective", "updateTime", "orgCode", "isVisible", "createTime", "categoryPid","skuId" ,"spuId","name","value"});
					
					
					
					goodsSkuVo.setSkuPropertyValues(skuPropertyValues);
					
					Double conPrice = mainSku.getSkuPrice();
					SkuCoupon coupon = getCanUsedCouponBySku(mainSku);
					if( null != coupon ){
						conPrice = mainSku.getSkuPrice()-coupon.getMoney();
					}
					goodsSkuVo.setConPrice(conPrice);
					
					dataMap.put("sku", goodsSkuVo);
					
					resultMap.put(DATA, dataMap);
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_NOT_FIND_ERROR_CODE;
					errorMsg = PRODUCT_NOT_FIND_ERROR_MSG;
				}
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "index", e.toString(), "根据商品的spuId获得商品的属性", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	@RequestMapping(value = "/getskuPropertys")
	@ResponseBody
	public Map<String, Object> getskuPropertys(HttpServletRequest request, HttpServletResponse response, String id) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if (StringHelper.isNotBlank(id)) {
				
				GoodsSpu spu = goodsSpuService.get(id);
				
				if( null != spu ){
					
					Map<String, Object> dataMap = new HashMap<String, Object>();
					
					List<GoodsPropertyVo> propertys = new ArrayList<GoodsPropertyVo>();
					
					List<SkuPropertyVo> propertyVos = getGroupPropertyVoBySpu(spu);
					
					/*List<SkuPropertyVo> propertyVos = getGroupPropertyVoBySpuNew(spu);*/
					
					
					if( propertyVos.size()>0 ){
						for( SkuPropertyVo temp : propertyVos ){
							GoodsPropertyVo vo = new GoodsPropertyVo();
							
						/*	vo.setPropertyId(temp.getId());*/
							vo.setPropertyName(temp.getName());
							vo.setPropertyNameID(temp.getNameId());
							/*vo.setPropertyvalue(temp.getValue());
							vo.setPropertyvalueId(temp.getValueId());*/
							
							//查找该属性下的值总共多少
							/*List<PropertyValueVo> valuesVos = getPropertyValueVosByNameId(temp.getNameId());*/
							/*List<PropertyValueVo> valuesVos = getPropertyValueVosByNameId(temp.getNameId());*/
							List<PropertyValueVo> valuesVos = getPropertyValueVosByNameIdNew(temp.getNameId(),spu.getId());
							
							vo.setPropertyValues(valuesVos);
							propertys.add(vo);
						}
					}
					
					dataMap.put("propertys", propertys);
					
					GoodsSku mainSku = getMainSkuBySpu(spu);
					GoodsSkuVo goodsSkuVo = new GoodsSkuVo();
					goodsSkuVo.setSkuId(mainSku.getId());
					goodsSkuVo.setPrice(mainSku.getSkuPrice());
					goodsSkuVo.setInventory(mainSku.getTotalInventory());
					goodsSkuVo.setSkuImage(mainSku.getSkuBanners());
					
					List<SkuProperty> skuPropertys = getSkuPropertyValueBySku(mainSku);
					List<Map<String, Object>> skuPropertyValues = ValueHelper.tranList2MapList(skuPropertys, new String[] { "id", "note", "reorder",
							"createUser", "isEffective", "updateTime", "orgCode", "isVisible", "createTime", "categoryPid","skuId" ,"spuId","name","value"});
					
					
					
					goodsSkuVo.setSkuPropertyValues(skuPropertyValues);
					
					Double conPrice = mainSku.getSkuPrice();
					SkuCoupon coupon = getCanUsedCouponBySku(mainSku);
					if( null != coupon ){
						conPrice = mainSku.getSkuPrice()-coupon.getMoney();
					}
					goodsSkuVo.setConPrice(conPrice);
					
					dataMap.put("sku", goodsSkuVo);
					
					resultMap.put(DATA, dataMap);
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_NOT_FIND_ERROR_CODE;
					errorMsg = PRODUCT_NOT_FIND_ERROR_MSG;
				}
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "index", e.toString(), "根据商品的spuId获得商品的属性", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	

	/**
	 * 根据商品的spuId和款式获得商品的sku信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getSkuByProperty")
	@ResponseBody
	public Map<String, Object> propertyDetail(HttpServletRequest request, HttpServletResponse response,String spuId,String nameValueIds) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if ( StringHelper.isNotBlank(spuId) && StringHelper.isNotBlank(nameValueIds) ) {
				
				GoodsSpu spu = goodsSpuService.get(spuId);
				if( null != spu ){
					
					List<SkuPropertyVo> propertyVos = getGroupPropertyVoBySpu(spu);
					String[] splitValues = nameValueIds.split(",");
					//判断是否全属性
					if( splitValues.length == propertyVos.size() ){
						GoodsSkuExample example = new GoodsSkuExample();
						com.itic.mall.system.goods.goodssku.persistence.model.GoodsSkuExample.Criteria criteria = example.createCriteria();
						criteria.andIsEffectiveEqualTo(DBConst.TRUE);
						criteria.andParamQueryEqualTo(nameValueIds);
						criteria.andSpuIdEqualTo(spuId);
						criteria.andTotalInventoryGreaterThan(0);
						List<GoodsSku> list = goodsSkuService.list(example);
						if( list.size() > 0 ){
						    GoodsSku goodsSku = list.get(0);
						    GoodsSkuVo vo = new GoodsSkuVo();
						    vo.setSkuId(goodsSku.getId());
							vo.setPrice(goodsSku.getSkuPrice());
							vo.setSkuImage(goodsSku.getSkuBanners());
							vo.setInventory(goodsSku.getTotalInventory());
							
							Double conPrice = goodsSku.getSkuPrice();
							SkuCoupon coupon = getCanUsedCouponBySku(goodsSku);
							if( null != coupon ){
								conPrice = goodsSku.getSkuPrice()-coupon.getMoney();
							}
							vo.setConPrice(conPrice);
							
							List<SkuProperty> skuPropertys = getSkuPropertyValueBySku(goodsSku);
							List<Map<String, Object>> skuPropertyValues = ValueHelper.tranList2MapList(skuPropertys, new String[] { "id", "note", "reorder",
									"createUser", "isEffective", "updateTime", "orgCode", "isVisible", "createTime", "categoryPid","skuId" ,"spuId","name","value"});
							
							String showName  = "";
							if( skuPropertys.size()>0 ){
								for( SkuProperty temp: skuPropertys ){
									showName += temp.getValue() + " ";
								}
							}
							vo.setShowName(showName);
							
							vo.setSkuPropertyValues(skuPropertyValues);
							
							resultMap.put(DATA, vo);
							
							errorCode = SUCCESS_ERROR_CODE;
							errorMsg = SUCCESS_ERROR_MSG;
						}else{
							errorCode = PRODUCT_DATA_ERROR_CODE;
							errorMsg = PRODUCT_DATA_ERROR_MSG;
						}
					}else{
						errorCode = PRODUCT_PROPERTY_LESS_ERROR_CODE;
						errorMsg = PRODUCT_PROPERTY_LESS_ERROR_MSG;
					}
				}else{
					errorCode = PRODUCT_NOT_FIND_ERROR_CODE;
					errorMsg = PRODUCT_NOT_FIND_ERROR_MSG;
				}
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "index", e.toString(), "APP查找友惠，京东，天猫，淘宝等商品信息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	

	/**
	 * 根据属性名称的id获得所有的属性值信息
	 * @param nameId
	 * @return
	 */
	/*private List<PropertyValueVo> getPropertyValueVosByNameId(String nameId) {
		return propertyValueService.getPropertyValueVosByNameId(nameId);
	}*/
	
	private List<PropertyValueVo> getPropertyValueVosByNameIdNew(String nameId,String spuid) {
		return propertyValueService.getPropertyValueVosByNameIdNew(nameId,spuid);
	}

	
	/**
	 * 根据商品Spu查看商品规格
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getSpecs")
	@ResponseBody
	public Map<String, Object> getSpecs(HttpServletRequest request, HttpServletResponse response, String id) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if (StringHelper.isNotBlank(id)) {
				GoodsSpu goodsSpu = goodsSpuService.get(id);
				if( null != goodsSpu ){
					List<SpuSpec> list = getSpecsBySpu(goodsSpu);
					resultMap.put(DATA, ValueHelper.tranList2MapList(list, new String[] { "id","createUser","createTime", "isEffective", "updateTime", "orgCode","note","reorder","spuId" }));
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_NOT_FIND_ERROR_CODE;
					errorMsg = PRODUCT_NOT_FIND_ERROR_CODE;
				}
				
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "getSpecs", e.toString(), "根据商品Spu查看商品规格", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 根据商品Spu查看商品规格
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getSpuFeedbacks")
	@ResponseBody
	public Map<String, Object> getSpuFeedbacks(HttpServletRequest request, HttpServletResponse response, String id, String type ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if (StringHelper.isNotBlank(id)) {
				GoodsSpu goodsSpu = goodsSpuService.get(id);
				if( null != goodsSpu ){
					Map<String, Object> dataMap = new HashMap<String, Object>();
					
					SpuFeedbackExample example = new SpuFeedbackExample();
					example.setOrderByClause("CREATE_TIME DESC");
					com.itic.mall.system.goods.spufeedback.persistence.model.SpuFeedbackExample.Criteria criteria = example.createCriteria();
					criteria.andIsEffectiveEqualTo(DBConst.TRUE);
					criteria.andSpuIdEqualTo(id);
					if( StringHelper.isNotBlank(type) ){
						criteria.andImagesIsNotNull();
					}
					this.handlePageQueryDefault(request, example);
					int imageCount = getImageFeedbackCountsBySpu(goodsSpu);
					int count = getFeedbackCountsBySpu(goodsSpu);
					
					List<SpuFeedback> list = spuFeedbackService.list(example);
					
					dataMap.put("total", count);
					dataMap.put("imageTotal", imageCount);
					dataMap.put("isMore", isMore(request, count));
					dataMap.put("list", ValueHelper.tranList2MapList(list, new String[] { "createUser", "isEffective", "updateTime", "orgCode","note","reorder","spuId" }));
					resultMap.put(DATA, dataMap);
					
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_NOT_FIND_ERROR_CODE;
					errorMsg = PRODUCT_NOT_FIND_ERROR_CODE;
				}
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "getSpecs", e.toString(), "根据商品Spu查看商品规格", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 根据佣金比例获得佣金多少
	 * @param percent
	 * @param conPrice
	 * @return
	 */
	private Double getWlCommissionByConPrice(Double percent, Double conPrice) {
		double mul = NumericHelper.mul(conPrice, percent);
		double div = NumericHelper.div(mul, 100,2);//后期改1.8
		return div;
	}

	
	/**
	 * 
	 * @param mainSku
	 * @return
	 */
	public SkuCommission getWlCommissionBySku( GoodsSku mainSku ){
		SkuCommission commission = null;
		SkuCommissionExample example = new SkuCommissionExample();
		com.itic.mall.system.goods.skucommission.persistence.model.SkuCommissionExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);//是否删除
		criteria.andIsUsedEqualTo(DBConst.TRUE);//是否有效
		criteria.andSkuIdEqualTo(mainSku.getId());
		criteria.andCommissionTypeEqualTo("WL");//获取无线应用的佣金
		List<SkuCommission> list = skuCommissionService.list(example);
		if( list.size()>0 ){
			SkuCommission temp = list.get(0);
			if( nowIsBetweenStarttimeAndEndtime( temp.getStartTime(),temp.getEndTime() ) ){
				commission = temp;
			}
		}
		return commission;
	}
	
	
	/**
	 * 获得商品的主款优惠券信息（不判断优惠券是否在有效期内）
	 * @param spu
	 * @return
	 */
	public SkuCoupon getSkuCouponBySku( GoodsSku mainSku ){
		SkuCoupon coupon = null;
		SkuCouponExample example = new SkuCouponExample();
		com.itic.mall.system.goods.skucoupon.persistence.model.SkuCouponExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);//是否删除
		criteria.andIsUsedEqualTo(DBConst.TRUE);//是否有效
		criteria.andSkuIdEqualTo(mainSku.getId());
		List<SkuCoupon> list = skuCouponService.list(example);
		if( list.size()>0 ){
			coupon = list.get(0);
		}
		return coupon;
	}
	
	/**
	 * 获得商品的主款优惠券信息（需要判断优惠券是否在有效期内）
	 * @param spu
	 * @return
	 */
	public SkuCoupon getCanUsedCouponBySku( GoodsSku sku ){
		SkuCoupon coupon = null;
		SkuCouponExample example = new SkuCouponExample();
		com.itic.mall.system.goods.skucoupon.persistence.model.SkuCouponExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);//是否删除
		criteria.andIsUsedEqualTo(DBConst.TRUE);//是否有效
		criteria.andSkuIdEqualTo(sku.getId());
		List<SkuCoupon> list = skuCouponService.list(example);
		if( list.size()>0 ){
			SkuCoupon temp = list.get(0);
			if( nowIsBetweenStarttimeAndEndtime( temp.getStartTime(),temp.getEndTime() ) ){
				coupon = temp;
			}
		}
		return coupon;
	}
	
	/**
	 * 获得商品的主款优惠券信息（需要判断优惠券是否在有效期内）
	 * @param spu
	 * @return
	 */
	public List<SkuCoupon> getCanUsedCouponBySpu( GoodsSpu spu ){
		SkuCouponExample example = new SkuCouponExample();
		com.itic.mall.system.goods.skucoupon.persistence.model.SkuCouponExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);//是否删除
		criteria.andIsUsedEqualTo(DBConst.TRUE);//是否有效
		criteria.andSpuIdEqualTo(spu.getId());
		List<SkuCoupon> list = skuCouponService.list(example);
		return list;
	}
	
	
	/**
	 * 获得商品的主款优惠券信息（需要判断优惠券是否在有效期内）
	 * @param spu
	 * @return
	 */
	public List<Map<String, Object>> getCanUsedCouponBySpuAndType( GoodsSpu spu,String type ){
		SkuCouponExample example = new SkuCouponExample();
		com.itic.mall.system.goods.skucoupon.persistence.model.SkuCouponExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);//是否删除
		criteria.andIsUsedEqualTo(DBConst.TRUE);//是否有效
		criteria.andSpuIdEqualTo(spu.getId());
		if( StringHelper.isNotBlank(type) ){
			criteria.andTypeEqualTo(type);
		}
		List<SkuCoupon> list = skuCouponService.list(example);
		List<Map<String, Object>> tranList2MapList = ValueHelper.tranList2MapList(list, new String[] { "createUser","createTime", "isEffective", "updateTime", "orgCode","note","reorder","spuId","isUsed","limitUserCount","totalUsedCount","totalCount","totalUsedCount","limitUserCount","skuId","startTime","endTime" });
		return tranList2MapList;
	}
	
	
	/**
	 * 获得商品的SPU的主款式
	 * @param spu
	 * @return
	 */
	public GoodsSku getMainSkuBySpu( GoodsSpu spu ){
		GoodsSku mainSku = null;
		GoodsSkuExample example = new GoodsSkuExample();
		com.itic.mall.system.goods.goodssku.persistence.model.GoodsSkuExample.Criteria criteria = example
				.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);// 是否有效
		criteria.andIsMainEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spu.getId());
		
		List<GoodsSku> list = goodsSkuService.list(example);// 数据list
		if( list.size()>0 ){
			mainSku = list.get(0);
		}
		return mainSku;
	}
	
	/**
	 * 判断当前时间是否在时间段
	 * @param start
	 * @return
	 */
	public boolean nowIsBetweenStarttimeAndEndtime( Date start, Date end ){
		boolean result = false;
		
		Date now = new Date();
		
		if( null != start && null != end ){
			if(DateHelper.isInStartTimeAndStopTime(now, start, end)){
				result = true;
			}
		}
		
		if( null != start && null == end ){
			if(DateHelper.isGreaterDate(now, start)){
				result = true;
			}
		}
		
		if( null == start && null != end ){
			if(DateHelper.isGreaterDate(end, now)){
				result = true;
			}
		}
		
		return result;
	}
	
	/**
	 * 获取不能购买的提示图片地址(需要判断是否在开始时间与结束时间)
	 * @return
	 */
	public String getBuyTipBySpu( GoodsSpu spu ){
		String result = "";
		SpuOpenExample example = new SpuOpenExample();
		com.itic.mall.system.goods.spuopen.persistence.model.SpuOpenExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andIsUsedEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spu.getId());
		List<SpuOpen> list = spuOpenService.list(example);
		if( list.size()>0 ){
			SpuOpen temp = list.get(0);
			if( nowIsBetweenStarttimeAndEndtime( temp.getStartTime(),temp.getEndTime() ) ){
				result = temp.getImage();
			}
		}
		return result;
	}
	
	/**
	 * 商品详情展示的时候展示属性组
	 * @param spu
	 * @return
	 */
	public String getGroupPropertyNameBySpu( GoodsSpu spu ){
		String result = "";
		List<String> list  = skuPropertyService.getGroupPropertyNameBySpuId(spu.getId());
		if( list.size() > 0 ){
			for( String temp: list ){
				result += temp + " ";
			}
		}
		return result;
	}
	
	/**
	 * 商品详情展示的时候展示属性组
	 * @param spu
	 * @return
	 */
	public List<String> getGroupPropertyIdBySpu( GoodsSpu spu ){
		List<String> result = skuPropertyService.getGroupPropertyIdBySpuId(spu.getId());
		return result;
	}
	
	/**
	 * 商品详情展示的时候展示属性组
	 * @param spu
	 * @return
	 */
	public List<SkuPropertyVo> getGroupPropertyVoBySpu( GoodsSpu spu ){
		List<SkuPropertyVo> result = skuPropertyService.getGroupPropertyVoBySpuId(spu.getId());
		return result;
	}
	
	public List<SkuPropertyVo> getGroupPropertyVoBySpuNew( GoodsSpu spu ){
		List<SkuPropertyVo> result = skuPropertyService.getGroupPropertyVoBySpuIdNew(spu.getId());
		return result;
	}
	
	/**
	 * 商品详情展示的时候展示属性组
	 * @param spu
	 * @return
	 */
	public List<SkuProperty> getPropertysBySpu( GoodsSpu spu ){
		SkuPropertyExample example = new SkuPropertyExample();
		example.setOrderByClause("REORDER ASC");
		com.itic.mall.system.goods.skuproperty.persistence.model.SkuPropertyExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spu.getId());
		List<SkuProperty> list = skuPropertyService.list(example);
		return list;
	}
	
	/**
	 * 获得商品的spu图片详情URL
	 * @param spu
	 * @return
	 */
	public String getSpuImageBySpu( HttpServletRequest request, GoodsSpu spu  ){
		String localhostName = IpAddressHelper.getLocalhostName(request);
		return localhostName+"/mobile/yh/spuImage?id="+spu.getId();
	}
	
	/**
	 * 根据商品的SpuId，属性名称id,属性值Id获得sku信息（这里可以做一个左链接查询）
	 * @param spuId
	 * @param nameId
	 * @param valueId
	 * @return
	 */
	public List<SkuProperty> getGoodsSkusByProperty( String spuId, String nameId, String valueId ){
		SkuPropertyExample example = new SkuPropertyExample();
		com.itic.mall.system.goods.skuproperty.persistence.model.SkuPropertyExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spuId);
		criteria.andNameIdEqualTo(nameId);
		criteria.andValueIdEqualTo(valueId);
		List<SkuProperty> list = skuPropertyService.list(example);
		return list;
	}
	
	/**
	 * 根据商品SKU获得哪些属性
	 * @param mainSku
	 * @return
	 */
	private List<SkuProperty> getSkuPropertyValueBySku(GoodsSku sku) {
		SkuPropertyExample example = new SkuPropertyExample();
		com.itic.mall.system.goods.skuproperty.persistence.model.SkuPropertyExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSkuIdEqualTo(sku.getId());
		List<SkuProperty> list = skuPropertyService.list(example);
		return list;
	}
	
	/**
	 * 获得商品的规格信息
	 * @param spu
	 * @return
	 */
	private List<SpuSpec> getSpecsBySpu( GoodsSpu spu ){
		SpuSpecExample example = new SpuSpecExample();
		example.setOrderByClause("REORDER ASC");
		com.itic.mall.system.goods.spuspec.persistence.model.SpuSpecExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spu.getId());
		List<SpuSpec> list = spuSpecService.list(example);
		return list;
	}
	
	/**
	 * 获取商品属性
	 * @author 王文鑫
	 * @date 2018年1月9日 上午11:31:01
	 * @param spu
	 * @return
	 */
	private List<SkuProperty> getSkuPropertyBySpu( String spuId ){
		List<SkuProperty> list = skuPropertyService.getSkuPropertyBySpu(spuId);
		return list;
	}
	
	private SkuProperty getSkuPropertyById( String Id ){
		SkuProperty skuProperty = skuPropertyService.getSkuPropertyById(Id);
		return skuProperty;
	}
	
	
	/**
	 * 通过spuId获取sku信息
	 * @author 王文鑫
	 * @date 2018年1月11日 下午3:20:27
	 * @param spuId
	 * @return
	 */
	private List<GoodsSku> getGoodsSkuBySpuId(String spuId ){
		
		GoodsSkuExample example = new GoodsSkuExample();
		com.itic.mall.system.goods.goodssku.persistence.model.GoodsSkuExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spuId);
		
		List<GoodsSku> list = goodsSkuService.list(example);
		
		return list;
	}
	
	
	/**
	 * 获得商品的规格信息
	 * @param spu
	 * @return
	 */
	private int getImageFeedbackCountsBySpu( GoodsSpu spu ){
		SpuFeedbackExample example = new SpuFeedbackExample();
		com.itic.mall.system.goods.spufeedback.persistence.model.SpuFeedbackExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spu.getId());
		criteria.andImagesIsNotNull();
		int count = spuFeedbackService.count(example);
		return count;
	}
	
	/**
	 * 获得商品的规格信息
	 * @param spu
	 * @return
	 */
	private int getFeedbackCountsBySpu( GoodsSpu spu ){
		SpuFeedbackExample example = new SpuFeedbackExample();
		com.itic.mall.system.goods.spufeedback.persistence.model.SpuFeedbackExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andSpuIdEqualTo(spu.getId());
		//criteria.andImagesIsNotNull();
		int count = spuFeedbackService.count(example);
		return count;
	}
	
	/**
	 * 根据规格id查询sku
	 * @author 王文鑫
	 * @date 2018年1月16日 上午10:49:35
	 * @param request
	 * @param response
	 * @param ParmQuery
	 * @return
	 */
	@RequestMapping(value = "/getGoodsSkuByParmQuery")
	@ResponseBody
	public Map<String, Object> getGoodsSkuByParmquery(HttpServletRequest request, HttpServletResponse response,String parmQuery) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if (StringHelper.isNotBlank(parmQuery)) {
				Map<String, Object> dataMap = new HashMap<String, Object>();
				
				List<GoodsSku> list = goodsSkuService.getGoodsSkuByParmquery(parmQuery);
				
				dataMap.put("list", ValueHelper.tranList2MapList(list, skuIgnoreProperties));
				
				resultMap.put(DATA, dataMap);
				
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("YhInterface", "getGoodsSkuByParmQuery", e.toString(), "根据商品Spu查看商品规格", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
}
